import 'package:backend.core/core/domain/entities/api/web/yookassa/api_yookassa_bank_card_info.dart';
import 'package:equatable/equatable.dart';
import 'package:backend.purchases/infrastructure/dtos/api/web/api_bank_card_info_dto.dart';
import 'package:backend.purchases/infrastructure/dtos/api/web/api_web_bank_card_type_dto.dart';

class ApiYookassaBankCardInfoDto extends Equatable implements ApiWebBankCardInfoDto {
  const ApiYookassaBankCardInfoDto._internal({
    required this.last4,
    required this.expirationMonth,
    required this.expirationYear,
    required this.cardTypeDto,
  });

  @override
  final String last4;

  @override
  final String expirationMonth;

  @override
  final String expirationYear;

  @override
  final ApiWebBankCardTypeDto cardTypeDto;

  @override
  List<Object?> get props {
    return [
      last4,
      expirationMonth,
      expirationYear,
      cardTypeDto,
    ];
  }

  factory ApiYookassaBankCardInfoDto.fromEntity(ApiYookassaBankCardInfo bankCardInfo) {
    final cardTypeDto = ApiWebBankCardTypeDto.fromEntity(bankCardInfo.cardType);

    return ApiYookassaBankCardInfoDto._internal(
      last4: bankCardInfo.last4,
      expirationMonth: bankCardInfo.expirationMonth,
      expirationYear: bankCardInfo.expirationYear,
      cardTypeDto: cardTypeDto,
    );
  }

  @override
  Map<String, dynamic> toJson() {
    return {
      kApiWebBankCardInfoLast4Key: last4,
      kApiWebBankCardInfoExpirationMonthKey: expirationMonth,
      kApiWebBankCardInfoExpirationYearKey: expirationYear,
      kApiWebBankCardInfoCardTypeKey: cardTypeDto.toString(),
    };
  }
}
